<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel=StyleSheet HREF="../stylesheet/stylesheet.css" TYPE="text/css"
	MEDIA=screen>
	<title>::The Resort Pub And Restaurant::</title>
<link rel="stylesheet" href="stylereport.css" type="text/css" />
<link rel="shortcut icon" href="../image/Letter-T.ico" />
</head>
<body>
<?php

include("../connect/connect.php");
include("../function/thaidate.php");

if($_POST['dateInput']!="" && $_POST['dateInput2']!=""){
	$dmy = $_POST["dateInput"];
	$d = substr($dmy, 0, 2);
	$m = substr($dmy, 3, 2);
	$y = substr($dmy, 6, 4);
	$date = ($y - 543) . '-' . $m . '-' . $d;
	//$date = date("Y-m-d", $adate);
	
	
	$dmy2 = $_POST["dateInput2"];
	$d2 = substr($dmy2, 0, 2);
	$m2 = substr($dmy2, 3, 2);
	$y2 = substr($dmy2, 6, 4);
	//$adate2 = strtotime("+1 day",strtotime(($y2 - 543) . '-' . $m2 . '-' . $d2));
	//$date2 = date("Y-m-d", $adate2);
	$date2 = ($y2 - 543) . '-' . $m2 . '-' . $d2;

	$Query = mysql_query("SELECT sale_datetime3,cus_name FROM sale WHERE stype_id = '4' AND sale_datetime3 BETWEEN '$date' AND '$date2' GROUP BY cus_name ORDER BY cus_name") or die ("Error");
}
?>
<h1>รายงาน OC พนักงาน</h1>
<h2>ตั้งแต่วันที่ <?php echo thai_date(strtotime($date))." ถึงวันที่ ". thai_date(strtotime($date2)); ?></h2>
<?php
$i=0;
while($row=mysql_fetch_array($Query)){
	$i++;
?>
<br /><font size="4"><strong><?php echo $row['cus_name']; ?></strong></font><br /><br />
<table class="listorder">
  <thead>
<tr>
<td width="5%">ลำดับ</td>
<td width="20%">วันที่</td>
<td>รายการ</td>
<td width="10%">หน่วยละ</td>
<td width="10%">จำนวน</td>
<td width="12%">ยอดเงิน</td>
</tr>
  </thead>
<?php

$num1 = 0;
	$dQuery = mysql_query("SELECT product.prod_name as prod_name,sale.sale_datetime3 as sale_datetime3,sum(sale.sale_qty) as sale_qty,sale.sale_price FROM sale,product WHERE sale.stype_id = '4' AND product.prod_id=sale.prod_id AND sale.cus_name = '".$row['cus_name']."' AND sale.sale_datetime3 BETWEEN '$date' AND '$date2' GROUP BY sale.cus_name,sale.prod_id,sale.sale_datetime3,sale.sale_price ORDER BY sale.sale_datetime3");
	while ($dRow = mysql_fetch_array($dQuery)){
	$num1++;
?>
<tr>
<td align="center"><?php echo $num1; ?></td>
<td align="center"><?php $ddate = strtotime($dRow['sale_datetime3']); echo thai_date($ddate); ?></td>
<td align="left" style="padding-left:10px"><?php echo $dRow['prod_name']; ?></td>
<td align="right" style="padding-right:10px"><?php echo "".number_format($dRow['sale_price'], 2,'.',','); ?></td>
<td align="right" style="padding-right:10px"><?php echo $dRow['sale_qty']; ?></td>
<td align="right" style="padding-right:10px"><?php $sale_discount1 = $dRow['sale_price']*$dRow['sale_qty']; 
echo "".number_format($sale_discount1, 2,'.',',');
?></td>
</tr>
<?php
	$strTotal1[$i]=$strTotal1[$i]+$sale_discount1;
}

?>
<tfoot>
  <tr>
    <td colspan="5" align="center">รวมเงิน</td>
    <td align="right" style="padding-right:10px"><?php echo "".number_format($strTotal1[$i], 2,'.',','); ?></td>
	</tr>
</tfoot>
</table><br />
<?php 
}
?>
<br /><input type="button" name="btnPrint" value="พิมพ์รายงาน" onclick="JavaScript:window.print();" /> <input type="button" name="btnClose" value="ปิดหน้าต่าง" onclick="JavaScript:window.close();" /><br /><br />
</body>
</html>
